//
//  LTMainTabBarController.m
//  weiboOC
//
//  Created by 刘涛 on 15/6/23.
//  Copyright © 2015年 tao6. All rights reserved.
//

#import "LTMainTabBarController.h"
#import "LTHomeTableViewController.h"
#import "LTMessageTableViewController.h"
#import "LTDiscoverTableViewController.h"
#import "LTProfileTableViewController.h"
#import "LTMainTabBar.h"

@interface LTMainTabBarController ()

@end

@implementation LTMainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    LTMainTabBar *MianTabBar = [[LTMainTabBar alloc] init];
    
    // 用KVC大招来替换只读属性
    [self setValue:MianTabBar forKey:@"tabBar"];
    
    [self addChildViewControllers];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (void)addChildViewControllers {
    [self addChildViewControllerVcName:@"LTHomeTableViewController" title:@"首页" imageName:@"tabbar_home"];
    [self addChildViewControllerVcName:@"LTMessageTableViewController" title:@"消息" imageName:@"tabbar_message_center"];
    [self addChildViewControllerVcName:@"LTDiscoverTableViewController" title:@"发现" imageName:@"tabbar_discover"];
    [self addChildViewControllerVcName:@"LTProfileTableViewController" title:@"我" imageName:@"tabbar_profile"];
    
}

- (void)addChildViewControllerVcName:(NSString *)vcName title:(NSString *)title imageName:(NSString *)imageName {
    // 1. 根据名称获取控制器类别
    Class cls = NSClassFromString(vcName);
    // 2. 根据类别来创建控制器
    UIViewController *vc = [[cls alloc] init];
    
//    NSLog(@"%@", vc);
    
    vc.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted", imageName]];

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    
    [self addChildViewController:nav];
    
    
    
    
}

@end
